#pragma once
#include <string>
#include <vector>
#include "json.hpp"



using json = nlohmann::json;

class Character;
class Methods;
class Effect;
class Monster
{
protected:
	std::string monsterName;
	std::string monsterInfo;

	int currentHealth;
	int maxHealth;
	int attack;
	int defense;

    int methods;
    Methods* m_;
public:
	Monster(std::string name, std::string info, int h, int at, int de,int methods=0);
    ~Monster();
    void Attack(Character& character);
	void OnTakeDamage(int value);
    void AttackEffect(int methods,Character& character);

	bool isAlive() const;
	std::string getName() const;
    std::string getInfo() const;
	int getDefense() const;
	int getCurrentHealth() const;
	int getMaxHealth() const;
	int getAttack() const; 
    int getMethods() const;

    void setMaxHealth(int h);
    void setCurrentHealth(int h);
    void setAttack(int a);
    void setDefense(int d);
    void setName(const std::string& name) { monsterName = name; }
    void setInfo(const std::string& info) { monsterInfo = info; }

    // 序列化为JSON
    json toJson() const {
        return {
            {"name", monsterName},
            {"Info", monsterInfo},
            {"maxHealth", maxHealth},
            {"currentHealth", currentHealth},
            {"attack", attack},
            {"defense", defense},
            {"methods",methods}
        };
    }
    

    // 从JSON反序列化
    static Monster fromJson(const json& j) {
       
        Monster monster(
            j["name"].get<std::string>(),
            j["Info"].get<std::string>(),
            j["maxHealth"].get<int>(),
            j["attack"].get<int>(),
            j["defense"].get<int>(),
            j["methods"].get<int>()
        );

        monster.currentHealth = j["currentHealth"].get<int>();
        return monster;
    }

    Monster(const Monster& other);
    Monster& operator=(const Monster& other);
    Monster(Monster&& other) noexcept;
    Monster& operator=(Monster&& other) noexcept;
};